from django.conf.urls.defaults import *
from django.contrib.auth.views import login, logout


from views import *
from contacts.models import *
from contacts.forms import *
from contacts.views import *
from contacts.views_obsolete import *
from contacts.authz import *

from dailylang.views import *

from django.contrib import admin
admin.autodiscover()

handler500 = 'djangotoolbox.errorviews.server_error'

urlpatterns = patterns('',
    (r'^admin/', include(admin.site.urls)),
    ('^_ah/warmup$', 'djangoappengine.views.warmup'),
    ('^$', 'django.views.generic.simple.direct_to_template',
     {'template': 'home.html'}),
    ('^hello/$', hello),
    ('^current-url/$', current_url),
    ('^insert-contact-type/$', insert_contact_type),
    ('^select-contact-type/$', select_records,
     {'model': ContactType,
      'redirect': '/new-contact-type/',
      'template': 'select-contact-type.html'
     }),
    ('^new-contact-type/$', new_record, 
     {'form': ContactTypeForm,
      'redirect': '/select-contact-type/',
      'template': 'new-contact-type-form.html'
     }),
    ('^del-contact-type/$', del_records,
     {'model': ContactType,
      'redirect': '/select-contact-type/'
     }),
    ('^edit-contact-type/(\d+)/$', edit_record, 
     {'model': ContactType, 
      'form': ContactTypeForm, 
      'redirect': '/select-contact-type/', 
      'template': 'edit-contact-type-form.html'
     }),
    ('^select-person/$', select_records,
     {'model': Person,
      'redirect': '/new-person/',
      'template': 'select-person.html'
     }),
    ('^new-person/$', new_record,
     {'form': PersonForm,
      'redirect': '/select-person/',
      'template': 'new-person-form.html'
     }),
    ('^del-person/$', del_records,
     {'model': Person,
      'redirect': '/select-person/'
     }),
    ('^edit-person/(\d+)/$', edit_parent,
      {'model': Person  , 
      'form': PersonForm, 
      'redirect': '/select-person/', 
      'template': 'edit-person-form.html',
      'child_model': Contact,
      'child_template': '/edit-contact-to-person/'
     }),
    ('^new-contact-to-person/(\d+)/$', new_child,
     {'parent_model': Person,
      'model': Contact, 
      'foreign': 'person',
      'form': ContactToPersonForm, 
      'redirect': '/edit-person/', 
      'template': 'new-contact-to-person-form.html'
     }),
    ('^edit-contact-to-person/(\d+),(\d+)/$', edit_child,
     {'parent_model': Person,
      'model': Contact, 
      'form': ContactForm, 
      'redirect': '/edit-person/', 
      'template': 'edit-contact-to-person-form.html'
     }),
    ('^del-contacts-to-person/(\d+)/$', del_child,
     {'model': Contact,
      'redirect': '/edit-person/'
     }),
    ('^main/', main_page),
    (r'^accounts/login/$', login),
    (r'^accounts/logout/$', logout),
    (r'^accounts/register/$', register),
    (r'^accounts/profile/$', profile),
    (r'^openid/', include('django_openid_auth.urls')),
    (r'^categories/(\d+)/(\d+)', categories),
)
